package com.bocai.kelala.ui.travel.main.ada;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bocai.kelala.R;
import com.bocai.kelala.bean.MessageBean;
import com.bocai.kelala.ui.travel.main.presenter.MessagePresenter;
import com.bocai.kelala.widget.ListBaseAdapter;
import com.bocai.mybase.base.BaseRecyclerViewHolder;


/**
 * Created by yuanfei on 2017/7/8.
 */

public class MessageAda extends ListBaseAdapter<MessageBean.MessagesBean> {



    private MessagePresenter presenter;

    private OnItemClickedListener onItemClickedListener;

    public MessageAda(Context context, MessagePresenter presenter) {
        super(context);
        this.presenter = presenter;
    }
    public void setOnItemClickedListener(OnItemClickedListener onItemClickedListener){
        this.onItemClickedListener = onItemClickedListener;
    }
    @Override
    public int getLayoutId() {
        return R.layout.item_message;
    }

    @Override
    public void onBindItemHolder(BaseRecyclerViewHolder holder, final int position) {

        TextView tvTitle = (TextView) holder.findView(R.id.tv_title);
        TextView tvContent = (TextView) holder.findView(R.id.tv_content);
        TextView tvData = (TextView) holder.findView(R.id.tv_data);
        LinearLayout llCircle = (LinearLayout) holder.findView(R.id.ll_circle);
        LinearLayout llDelete = (LinearLayout) holder.findView(R.id.ll_delete);
        LinearLayout llMessage = (LinearLayout) holder.findView(R.id.ll_message);

        tvTitle.setText(mDataList.get(position).getTitle());
        tvContent.setText(mDataList.get(position).getContent());
        tvData.setText(mDataList.get(position).getSendTime());
        if (mDataList.get(position).isIsRead()){
            llCircle.setVisibility(View.GONE);
        }else {
            llCircle.setVisibility(View.GONE);
        }

        llMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickedListener != null)
                    onItemClickedListener.onItemClicked(position);
            }
        });

        llDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presenter.deleteMessage(mDataList.get(position).getId(),position);
            }
        });

    }
    public interface OnItemClickedListener {
        void onItemClicked(int index);
    }
}
